<?php
session_start();

require("includes/funciones.inc.php");
require("includes/constants.php");

$DB = NewADOConnection('mysqlt');
$DB->Connect();
$DB->Execute("SET NAMES utf8;");
//$DB->debug=true;

//LOGIN
if(!empty($_POST['usuario']))
{
	$mcrypt = new MCrypt();
	$encryptedPass = $mcrypt->encrypt($_REQUEST["password"]);
			
	$strSQL = "SELECT * FROM usuarios WHERE usuario = '".$_REQUEST['usuario']."' AND password = '".$encryptedPass."'";
	
	$rsUsuario = $DB->Execute($strSQL); 
	if (!$rsUsuario->EOF)
	{
		$_SESSION['idUsuario'] = $rsUsuario->fields("idUsuario");
		$_SESSION['nombreUsuario'] = $rsUsuario->fields("usuario");
		$_SESSION['nombreCompleto'] = $rsUsuario->fields("nombreCompleto");
		$_SESSION['idTipoUsuario'] = $rsUsuario->fields("idTipoUsuario");
			
		Header("Location: principal.php");
		exit();
	}
}
?>
<!DOCTYPE HTML>
<html>

<head>
	<title>--::[ Finta Pelle Gesti&oacute;n ]::--</title>
  	<meta name="description" content="order online with android" />
  	<meta name="keywords" content="order, online, android" />
  	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  	<link rel="stylesheet" type="text/css" href="css/style.css" />
  	<!-- modernizr enables HTML5 elements and feature detects -->
  	<script type="text/javascript" src="js/modernizr-1.5.min.js"></script>

	<!-- Javascript -->  	
  	<script type="text/javascript" src="js/jquery/jquery-1.7.1.min.js"></script>
  	<script type="text/javascript" src="js/jquery/jquery-ui-1.8.16.custom.min.js"></script>
  	  	
  	<!-- Data Tables -->
	<script src="js/datatables/js/jquery.dataTables.js" type="text/javascript" ></script>
	
	<!-- Form Script -->
	<script type="text/javascript" src="js/login.js"></script>
  	<script type="text/javascript" src="js/utils.js"></script>
	
  	<!-- Iniciar Formulario -->
  	<script type='text/javascript'>
	$(document).ready(
		function() {
			setTimeout(function(){focus_login()}, 100);
			<?php if (!empty($_POST['usuario']) && $rsUsuario->EOF) { ?>
				$_showMessage('ERR', 'ERROR', 'Nombre de Usuario o Clave Incorrecta');
			<?php } ?>
	});
	</script>
</head>

<body>
	<div id="main">
		<header>
      		<nav>
        		<div id="menu_container">
        		</div>
      		</nav>
    	</header>
		<div id="site_content">
			<div class="content">
			<h1>Ingreso al Sistema</h1>
			<form id="frmLogin" name="frmLogin" method="post" action="" onsubmit="return $_validateLoginForm();">
	         	<div class="form_settings">
	            	<p><span>Usuario</span><input class="contact" type="text" name="usuario" id="usuario" /></p>
	            	<p><span>Clave</span><input class="contact" type="password" name="password" id="password" /></p>
	            	<p style="padding-top: 15px"><span>&nbsp;</span><input class="submit" type="button" onclick="$('#frmLogin').submit();" name="login_submitted" name="login_submitted" value="Ingresar" /></p>
	          	</div>
	        </form>
			</div>
		</div>
	    <footer>
	      <p>FINTAPELLE SRL 2013 TODOS LOS DERECHOS RESERVADOS | Copyright &copy; Federico N. Pisarello</p>
	    </footer>
	</div>
</body>

<!-- Global Message -->
<div id="globalMess"> 
	<div class="img"></div>
	<div id="globalMessImgClose" class="imgClose"></div>
	<div id="tituloMess" class="msgTitulo">TITULO</div>
	<p id="textoMess" class="msgTexto">MENSAJE</p>
</div>

</html>